<?php

namespace Api\Controller;

class UpdataController extends ApiController {

    private $token;
    private $deviceid;
    private $user_id;
    private $error_uploads;

    function __construct() {
        parent::__construct();
        $this->token = I('request.token');
        $this->deviceid = I('request.deviceid');
        $this->user_id = $this->verify_token($this->token, $this->deviceid);
        $this->error_uploads = array(
            'null' => '没有图片上传',
        );
    }

    private function is_power($user_id, $class_id, $power) {
        $Member = D('Member');
        $member = $Member->getMembyids($user_id, $class_id);
        if (empty($member['power']) || $member['power'] < $power) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function upimage() {
        $config = array(
            'mimes' => '', //允许上传的文件MiMe类型
            'maxSize' => 20 * 1024 * 1024, //上传的文件大小限制 (0-不做限制)
            'exts' => 'jpg,gif,png,jpeg', //允许上传的文件后缀
            'autoSub' => true, //自动子目录保存文件
            'subName' => array('date', 'Y-m-d'), //子目录创建方式，[0]-函数名，[1]-参数，多个参数使用数组
            'rootPath' => './Uploads/', //保存根路径
            'savePath' => '', //保存路径
            'saveName' => array('uniqid', ''), //上传文件命名规则，[0]-函数名，[1]-参数，多个参数使用数组
            'saveExt' => '', //文件保存后缀，空则使用原后缀
            'replace' => false, //存在同名是否覆盖
            'hash' => true, //是否生成hash编码
            'callback' => false, //检测文件是否存在回调函数，如果存在返回文件信息数组
        );
        $upload = new \Think\Upload($config); // 实例化上传类
        $fileinfo = $upload->upload($_FILES);
        if (!$fileinfo) {// 上传错误提示错误信息
            $this->error($upload->getError());
        } else {// 上传成功
            foreach ($fileinfo as $value) {
                $info[] = $value['savepath'] . $value['savename'];
            }

            $this->success(__FUNCTION__, $info);
        }
    }

}
